package com.lbn.monitor.app.history.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.lbn.monitor.R;
import com.lbn.monitor.api.model.RealTimeValue;
import com.lbn.monitor.util.DataUtils;
import com.lbn.monitor.util.String2Num;

import java.util.List;

import butterknife.BindView;
import indi.free.widgets.custom_recycler_view.BasePagerRecyclerAdapter;
import indi.free.widgets.custom_recycler_view.RecyclerViewHolder;

/**
 * @author 李炳南
 * @date 2017/3/6
 */
public class HistoryAdapter extends BasePagerRecyclerAdapter<RealTimeValue> {

    private String pollutant;
    private String standard;
    private int pollutantId;
    public HistoryAdapter(Context ctx, RecyclerView recyclerView, List<RealTimeValue> list) {
        super(ctx, recyclerView, list);
    }

    @Override
    public int getItemLayoutId() {
        return R.layout.layout_item_history;
    }

    @Override
    public void bindData(RecyclerViewHolder holder, int position, RealTimeValue item) {

        if(item==null){
            return;
        }

//        holder.getTextView(R.id.name).setText(item.getTreename()+"("+item.getDeviceMN()+")");
        holder.getTextView(R.id.time).setText(item.getDataTime());
//        holder.getTextView(R.id.wuran).setText("污染物 : "+pollutant);
        holder.getTextView(R.id.standard).setText(standard);

        TextView monitor = holder.getTextView(R.id.monitor);
//        if (pollutant.equals("烟尘")) {
//            monitor.setText("监测值 : "+item.getStr01_Avg());
//        } else if (pollutant.equals("硫化氢")) {
//            monitor.setText("监测值 : "+item.getStr05_Avg());
//        } else if (pollutant.equals("二氧化硫")) {
//            monitor.setText("监测值 : "+item.getStr02_Avg());
//        } else if (pollutant.equals("一氧化碳")) {
//            monitor.setText("监测值 : "+item.getStr04_Avg());
//        }

        String avg = DataUtils.getAvg(pollutantId,item);

        monitor.setText(TextUtils.isEmpty(avg)?"0":avg);

        if(String2Num.str2Double(avg)>String2Num.str2Double(standard)){
            monitor.setTextColor(Color.parseColor("#ff0000"));
        }else{
            monitor.setTextColor(Color.parseColor("#333333"));
        }

    }

    public void setStandard(String standard) {
        this.standard = standard;
    }

    public void setPollutant(String pollutant) {
        this.pollutant = pollutant;
    }

    public void setPollutantId(int pollutantId) {
        this.pollutantId = pollutantId;
    }
}
